package cn.enjoyedu.ch02.echo;

import java.util.concurrent.*;

public class FutureTest {
    static class Task implements Callable<String> {

        @Override
        public String call() throws Exception {
            return "call";
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {


        FutureTask<String> futureTask = new FutureTask<String>(new Task());
        new Thread(futureTask).start();
        System.out.println(futureTask.get());


        ExecutorService executor = Executors.newSingleThreadExecutor();


        FutureTask<String> futureTask1 = new FutureTask<>(new Task());
        executor.submit(futureTask1);

        executor.shutdown();
        System.out.println(futureTask1.get());

    }


}
